package com.becca.cake.core.excel.excelReader.impl;

import java.io.IOException;
import java.io.InputStream;

import jxl.Workbook;
import jxl.read.biff.BiffException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.becca.cake.core.excel.excelReader.ExcelReaderHandle;

/**
 * 抽象出Excel处理
 * @author hejinguo
 * @version $Id: AbsExcelReader.java, v 0.1 2014-4-21 下午10:50:03
 */
public abstract class AbsExcelReader<T> implements ExcelReaderHandle<T> {
    private static Log logger = LogFactory.getLog(AbsExcelReader.class);
    protected Class<T> clazz;

    public AbsExcelReader(Class<T> clazz) {
        this.clazz = clazz;
    }

    public Workbook getWorkBook(InputStream fileUpload) {
        Workbook book = null;
        try {
            book = Workbook.getWorkbook(fileUpload);
        } catch (BiffException e) {
            if (logger.isErrorEnabled()) {
                logger.error("根据 InputStream获得工作薄对象时BiffException流异常!", e);
            }
        } catch (IOException e) {
            if (logger.isErrorEnabled()) {
                logger.error("根据 InputStream获得工作薄对象时IO流异常!", e);
            }
        }
        return book;
    }
}
